package leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

public class number239 {
    public static void main(String[] args) {
        int[]res=maxSlidingWindow(new int[]{1, 3, -1, -3, 5, 3, 6, 7},3);
        System.out.println(Arrays.toString(res));
    }
    public static int[] maxSlidingWindow(int[] nums, int k) {
        if(k==0){
            return new int[]{};
        }
        if(nums.length<k){
            return new int[]{};
        }
        PriorityQueue<Integer> queue=new PriorityQueue<>((a,b)->b-a);
        int reLen=nums.length-k+1;
        int index=0;
        int[]reArr=new int[reLen];
        int l=0,r=k;
        for(int i=0;i<k;i++){
            queue.add(nums[i]);
        }
        reArr[index++]=queue.peek();
        while(r<nums.length){
            queue.remove(nums[l++]);
            queue.add(nums[r++]);
            reArr[index++]=queue.peek();
        }
        return reArr;
    }
}
